#include <bits/stdc++.h>
using namespace std;
struct ListNode {
    int val;
    ListNode* next;
    ListNode() :val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};
bool isReverseChild(ListNode* a, ListNode* b) {
    ListNode *na = a;
    ListNode *nb = b;
    vector<int> va, vb;
    while(na != nullptr) {
        va.emplace_back(na->val);
        na = na->next;
    }
    while(nb != nullptr) {
        vb.emplace_back(nb->val);
        nb = nb->next;
    }
    reverse(va.begin(), va.end());
    size_t gap = find(va.begin(), va.end(), vb[0]) - va.begin();
    int i = gap, j = 0;
    while(i < va.size() && j < vb.size()) {
        if(vb[j] != va[i]) return false; 
        else{
            ++i;
            ++j;
        } 
    }
    if(j == vb.size()) return true;
    if(i == va.size()) return false;
}